package com.procurement.material.controller;

import java.security.Security;
import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.security.utils.SecurityUtils;
import com.ruoyi.system.api.domain.PcmSupplier;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.procurement.material.domain.PcmMaterialSupplier;
import com.procurement.material.service.IPcmMaterialSupplierService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 物料供应商Controller
 * 
 * @author liyang
 * @date 2023-11-28
 */
@RestController
@RequestMapping("/supplier")
public class PcmMaterialSupplierController extends BaseController
{
    @Autowired
    private IPcmMaterialSupplierService pcmMaterialSupplierService;


    /**
     * 查询供应商
     */
    @RequiresPermissions("material:supplier:listing")
    @GetMapping("/listing")
    public  TableDataInfo  supplierList(){
        List<PcmSupplier> list = pcmMaterialSupplierService.supplierList();
        return getDataTable(list);
    };


    /**
     * 查询物料供应商列表
     */
    @RequiresPermissions("material:supplier:list")
    @GetMapping("/list")
    public TableDataInfo list(PcmMaterialSupplier pcmMaterialSupplier)
    {
        startPage();
        List<PcmMaterialSupplier> list = pcmMaterialSupplierService.selectPcmMaterialSupplierList(pcmMaterialSupplier);
        return getDataTable(list);
    }

    /**
     * 导出物料供应商列表
     */
    @RequiresPermissions("material:supplier:export")
    @Log(title = "物料供应商", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PcmMaterialSupplier pcmMaterialSupplier)
    {
        List<PcmMaterialSupplier> list = pcmMaterialSupplierService.selectPcmMaterialSupplierList(pcmMaterialSupplier);
        ExcelUtil<PcmMaterialSupplier> util = new ExcelUtil<PcmMaterialSupplier>(PcmMaterialSupplier.class);
        util.exportExcel(response, list, "物料供应商数据");
    }

    /**
     * 获取物料供应商详细信息
     */
    @RequiresPermissions("material:supplier:query")
    @GetMapping(value = "/{materialQualificationID}")
    public AjaxResult getInfo(@PathVariable("materialQualificationID") Long materialQualificationID)
    {
        return success(pcmMaterialSupplierService.selectPcmMaterialSupplierByMaterialQualificationID(materialQualificationID));
    }

    /**
     * 新增物料供应商
     */
    @RequiresPermissions("material:supplier:add")
    @Log(title = "物料供应商", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PcmMaterialSupplier pcmMaterialSupplier)
    {
        pcmMaterialSupplier.setSubmitter(SecurityUtils.getUserId());
        return toAjax(pcmMaterialSupplierService.insertPcmMaterialSupplier(pcmMaterialSupplier));
    }

    /**
     * 修改物料供应商
     */
    @RequiresPermissions("material:supplier:edit")
    @Log(title = "物料供应商", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PcmMaterialSupplier pcmMaterialSupplier)
    {
        return toAjax(pcmMaterialSupplierService.updatePcmMaterialSupplier(pcmMaterialSupplier));
    }

    /**
     * 删除物料供应商
     */
    @RequiresPermissions("material:supplier:remove")
    @Log(title = "物料供应商", businessType = BusinessType.DELETE)
	@DeleteMapping("/{materialQualificationIDs}")
    public AjaxResult remove(@PathVariable Long[] materialQualificationIDs)
    {
        return toAjax(pcmMaterialSupplierService.deletePcmMaterialSupplierByMaterialQualificationIDs(materialQualificationIDs));
    }
}
